/**
 * Created by graysoft on 2017/2/5.
 */
import React from "react";

//选项元素模块
class OptionElement extends React.Component{
    constructor(props){
        super(props);
    }
    render(){
        return <option id={this.props.id}>{this.props.name}</option>;
    }
}
//select元件模块
class SelectElement extends React.Component{
    constructor(props){
        super(props);
        this.handleChange = this.handleChange.bind(this);
        this.handleClick = this.handleClick.bind(this);
    }


    handleClick(e){
        if(this.props.handleClick){
            this.props.handleClick(e,this.props.localeType);
        }
    }

    handleChange(e){
        this.props.handleChange(e,this.props);
    }

    render(){
        let outputList = [];

        this.props.lists.forEach(function(el){
            outputList.push(<OptionElement id={el.code} key={el.code} name={el.name} />);
        });
        return (
            <select onClick={this.handleClick} onChange={this.handleChange}>
                {outputList}
            </select>
        );
    }
}

export default SelectElement;